athlete = codesters.Sprite("player1")
athlete.move_right(200)
athlete2 = codesters.Sprite("player2")
athlete2.move_right(100)
from codesters import Text
tester = TestManager()
stage.wait(1)
stage.set_axis(250)
paused = False
def hover():
x = stage.mouse_x()
y = stage.mouse_y()
if (x < -135 and x > -250) and (y < -190 and y > -250):
click_box.set_opacity(.7)
click_text.set_opacity(.7)
else:
click_box.set_opacity(1)
click_text.set_opacity(1)
def pause():
global paused
while not paused:
stage.wait(0.1)
paused = False
def pause_click(sprite):
global paused
paused = True
def hide_click():
click_box.hide()
click_text.hide()
def show_click():
click_box.show()
click_text.show()
def delete_click(sprite):
pass
def delete_mouse_move():
pass
def delete_interval():
pass
def delete_collision(sprite, hit_sprite):
pass
def unpause():
global paused
paused = True
def pause_box():
global paused
show_click()
while not paused:
stage.wait(0.1)
paused = False
hide_click()
# ######## DEMO STARTS #############
try:
stage.remove_sprite(athlete)
stage.remove_sprite(athlete2)
except:
tester.display_failure_message("Oops! Make sure you don't do anything to do the code in your editor!")
pause()
guide = codesters.Sprite("person2")
guide.say("Let's learn about how this code works!")
stage.wait(2)
click_box = codesters.Rectangle(-200, -220, 125, 60, "green", "black")
click_text = codesters.Text("Continue", -200, -220, "white")
click_box.event_click(pause_click)
stage.event_mouse_move(hover)
pause_box()
guide.say("Dot notation is when we assign actions to sprites with different variable names.")
stage.wait(2)
pause_box()
guide.say("And a variable name is the name of our sprite.")
stage.wait(2)
pause_box()
guide.say("Let's practice!")
stage.wait(1)
pause_box()
guide.move_down(200)
guide.say("Click on the variable name to change it.")
athlete = codesters.Sprite("player1", 0, -500)
athlete.set_size(0.5)
athlete.set_position(0, 0)
variable_text = Text("sprite", -200, 200, "orange")
equals_text = Text("=", -160, 200,)
codester_text = Text("codesters.Sprite(", -70, 200)
image_label_text = Text('"player1"', 50, 200, "green")
ending_paren_text = Text(")", 95, 200)
def image_label_click(sprite):
guide.say("Oops, that's the image label, not the variable!")
image_label_text.event_click(image_label_click)
variable_text.event_click(pause_click)
pause()
variable_text.event_click(delete_click)
image_label_text.event_click(delete_click)
variable_text.set_text("athlete")
guide.say("Nice!")
stage.wait(1)
guide.say("Now, let's use dot notation to move our sprite to the right.")
pause_box()
guide.say("First, drag the sprite's variable name to the yellow box.")
yellow_box = codesters.Rectangle(-200, 150, 75, 40, "yellow")
yellow_box.set_opacity(0.5)
def variable_click(sprite):
new_variable = variable_text.clone()
new_variable.set_text("athlete")
new_variable.set_color("orange")
variable_text.event_click(delete_click)
variable_text.event_click(variable_click)
variable_text.set_drag_on()
def interval():
x = variable_text.get_x()
y = variable_text.get_y()
if (x < (-200 + yellow_box.get_width()/2) and x > (-200 - yellow_box.get_width()/2)) and ((y > 150 - yellow_box.get_height()/2) and y < (150 + yellow_box.get_height()/2)):
stage.event_interval(delete_interval, 0.1)
variable_text.set_drag_off()
variable_text.go_to(-200, 150)
yellow_box.hide()
guide.say("Nice!")
unpause()
stage.event_interval(interval, 0.1)
pause()
guide.say("Nice!")
stage.wait(1)
pause_box()
guide.say("Let's now make our player sprite move right!")
stage.wait(2)
pause_box()
guide.say("Drag the .move_right() to the highlighted area to move the player sprite!")
move_right_text = Text(".move_right( )", -150, -150)
integer_text = Text("200", move_right_text.get_x() + 53, move_right_text.get_y(), "dodgerblue")
move_right_text.set_drag_on()
yellow_box.set_position(-90, 150)
yellow_box.set_width(150)
yellow_box.show()
def interval():
x = move_right_text.get_x()
y = move_right_text.get_y()
integer_text.set_position(x + 53, y)
if (x < (yellow_box.get_x() + yellow_box.get_width()/2) and x > (yellow_box.get_x() - yellow_box.get_width()/2)) and ((y > yellow_box.get_y() - yellow_box.get_height()/2) and y < (yellow_box.get_y() + yellow_box.get_height()/2)):
stage.event_interval(delete_interval, 0.1)
move_right_text.set_drag_off()
move_right_text.go_to(-90, 150)
integer_text.set_position(move_right_text.get_x() + 53, move_right_text.get_y())
yellow_box.hide()
unpause()
stage.event_interval(interval, 0.01)
pause()
guide.say("Nice!")
athlete.move_right(200)
stage.wait(1)
guide.say("See how the sprite moved to the right 200 pixels when you put the .move_right() command at the end of its name?")
pause_box()
guide.say("Let's practice one more time!")
stage.wait(1)
pause_box()
athlete2 = codesters.Sprite("player2", 0, -500)
athlete2.set_size(0.5)
athlete2.set_position(25, 0)
variable_text = Text("athlete2", -200, 100, "orange")
equals_text = Text("=", -155, 100,)
codester_text = Text("codesters.Sprite(", -65, 100)
image_label_text = Text('"player2"', 55, 100, "green")
ending_paren_text = Text(")", 100, 100)
stage.wait(1)
variable_text = Text("athlete2", -200, 100, "orange")
variable_text.move_down(50)
guide.say("Drag the .move_right() to the highlighted area to move our second player sprite!")
move_right_text = Text(".move_right( )", -150, -150)
integer_text = Text("100", move_right_text.get_x() + 53, move_right_text.get_y(), "dodgerblue")
move_right_text.set_drag_on()
yellow_box.set_position(-80, 50)
yellow_box.set_width(150)
yellow_box.show()
def interval():
x = move_right_text.get_x()
y = move_right_text.get_y()
integer_text.set_position(x + 53, y)
if (x < (yellow_box.get_x() + yellow_box.get_width()/2) and x > (yellow_box.get_x() - yellow_box.get_width()/2)) and ((y > yellow_box.get_y() - yellow_box.get_height()/2) and y < (yellow_box.get_y() + yellow_box.get_height()/2)):
stage.event_interval(delete_interval, 0.1)
move_right_text.set_drag_off()
move_right_text.go_to(-85, 50)
integer_text.set_position(move_right_text.get_x() + 53, move_right_text.get_y())
yellow_box.hide()
unpause()
stage.event_interval(interval, 0.01)
pause()
athlete2.move_right(100)
guide.say("Nice!")
stage.wait(1)
guide.say("See how the second sprite (not the first) moved to the right 100 pixels when you put the .move_right() command at the end of its name?")
stage.wait(3)
pause_box()
guide.say("Nice job!")
tester.display_success_message("Great job! Click Submit and Next to move on!")